<template>
	<!-- 遍历userMenu, 获取一级菜单 -->
	<template v-for="menu in menuData.userMenu" :key="menu._id">
		<!-- el-sub-menu 代表父菜单 -->
		<el-sub-menu
			v-if="menu.children !== undefined && menu.children.length > 0 && menu.children[0].menuType === 1"
			:index="menu.path"
		>
			<template #title>
				<el-icon><component :is="menu.icon.split('-').pop()" /></el-icon>
				<span>{{ menu.menuName }}</span>
			</template>
			<!-- 递归展示 -->
			<tree-menu :userMenu="menu.children" />
		</el-sub-menu>
		<!-- el-menu-item 代表子菜单 -->
		<el-menu-item
			v-else-if="menu.children !== undefined && menu.children.length > 0 && menu.children[0].menuType === 2"
			:index="menu.path"
			>{{ menu.menuName }}</el-menu-item
		>
	</template>
</template>
<!-- frontend\src\components\TreeMenu.vue -->
<script setup>
import { Promotion, Setting } from "@element-plus/icons-vue";

// 定义从父组件接收的属性
const menuData = defineProps({
	userMenu: {
		type: Array,
	},
});
</script>
<style lang="scss" scoped></style>
